﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using Windows.ApplicationModel.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using douban.app.Annotations;
using douban.app.Views;

namespace douban.Core.ViewModels
{
    public abstract class VmBase : INotifyPropertyChanged
    {

        protected VmBase()
        {
        }

        public Frame AppFrame => Window.Current.Content as Frame;

        /// <summary>
        /// 直接转向另外一个页面
        /// </summary>
        /// <param name="type">页面的Type</param>
        /// <param name="parameter"></param>
        /// <returns>Task</returns>
        public async Task Navigate(Type type , System.Object parameter =null)
        {
            await CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal
                , () => { AppFrame?.Navigate(type,  parameter); });
        }


        public event PropertyChangedEventHandler PropertyChanged;

        [NotifyPropertyChangedInvocator]
        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }


        public abstract void OnNavigatedTo(NavigationEventArgs e);

        public abstract void OnNavigatedFrom(NavigationEventArgs e);
    }
}
